package com.excellence.controller;

import com.excellence.datamodel.Result;
import com.excellence.pojo.Problem;
import com.excellence.service.ProblemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author 沈秉璋
 * @ClassName ProblemController
 * @Description TODO
 * @date 2024/4/8 11:40
 * @Version 1.0
 */
//@Controller
//@ResponseBody
@RestController
@RequestMapping("/api/problem")
public class ProblemController {
    @Autowired
    private ProblemService problemService;

    @PutMapping("/deleteByKey")
    Result deleteByKey(Long id){
        int res = problemService.deleteByKey(id);
        return Result.success(res);
    }

    @DeleteMapping("/deleteByPrimaryKey")
    Result deleteByPrimaryKey(Long id){
        int res = problemService.deleteByPrimaryKey(id);
        return Result.success(res);
        //没测
    }
    @PostMapping("/insert")
    Result insert(Problem record, @RequestParam(value = "files",required = false) List<MultipartFile> files){
        int res = problemService.insert(record, files);
        return Result.success(res);
    }

    @PostMapping("/insertSelective")
    Result insertSelective(Problem record, @RequestParam(value = "files",required = false) List<MultipartFile> files){
        int res = problemService.insertSelective(record, files);
        return Result.success(res);
        //没测

    }

    @GetMapping("/selectByPrimaryKey")
    Result selectByPrimaryKey(Long id){
        Problem res = problemService.selectByPrimaryKey(id);
        return Result.success(res);

    }

    @GetMapping("/selectAll")
    Result selectAll(){
        List<Problem> res = problemService.selectAll();
        return Result.success(res);
    }

    @PutMapping("/updateByPrimaryKeySelective")
    Result updateByPrimaryKeySelective(Problem record, @RequestParam(value = "files",required = false) List<MultipartFile> files){
        int res = problemService.updateByPrimaryKeySelective(record, files);
        return Result.success(res);
        //没测
    }

    @PutMapping("/updateByPrimaryKey")
    Result updateByPrimaryKey(Problem record, @RequestParam(value = "files",required = false) List<MultipartFile> files){
        int res = problemService.updateByPrimaryKey(record, files);
        return Result.success(res);
        //没测
    }
}
